package com.docwei.thansgank.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.docwei.thansgank.R;
import com.docwei.thansgank.callback.ResultBean;

import java.util.List;

import static com.docwei.thansgank.R.id.webView;

/**
 * Created by tobo on 17/7/24.
 */

public class MyXiuXiAdapter extends RecyclerView.Adapter<MyXiuXiAdapter.MyViewHolder> {
    public List<ResultBean.GankBean> mList;
    public Context mContext;

    public MyXiuXiAdapter(List<ResultBean.GankBean> list, Context context) {
        mList = list;
        mContext = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_xiuxi, parent, false);
        return new MyViewHolder(view,mContext);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        ResultBean.GankBean bean = mList.get(position);
        holder.mTv_title.setText(bean.getDesc());
        holder.mWebView.loadUrl(bean.getUrl());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView mTv_title;

        WebView mWebView;
        public MyViewHolder(View itemView,Context context) {
            super(itemView);
             mTv_title = (TextView) itemView.findViewById(R.id.desc);
             mWebView= (WebView) itemView.findViewById(webView);
            mWebView.getSettings().setJavaScriptEnabled(true);
            mWebView.setWebViewClient(new WebViewClient());
        }
    }
}
